clear
clear matrix
set more off
local pathdata "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\DataN\Mapa"
cd "`pathdata'"

*shp2dta using Muni_2012gw, database(MEX) coordinates(MEX_coord)  gencentroids(c) genid(id) replace

use MEX.dta, clear
describe
gen Clave = CVE_ENT + CVE_MUN
destring Clave, replace

merge 1:1 Clave using "MunTerremoto_2017"
replace earthquake=0 if earthquake==.
drop _merge
sort Clave
label define equake 0 "No Impact" 1 "Impact"
label values earthquake equake

replace earthquake = 0 if Clave==21211
replace earthquake = 1 if Clave==20327
replace earthquake = 1 if Clave==20334
replace earthquake = 1 if Clave==30210
replace earthquake = 1 if Clave==30091

merge 1:1 Clave using "IM2015"
drop _merge
sort Clave

rename Clave clave 
merge clave using "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\DataN\Intensidad.dta"
rename clave Clave

replace magnitud1 = 8 if Clave==20066
replace magnitud1 = 8 if Clave==20327
replace magnitud1 = 5 if Clave==20334
replace magnitud1 = 4 if Clave==30210
replace magnitud1 = 4 if Clave==30091
replace magnitud1 = 7 if magnitud1 == 6.5

drop _merge
sort Clave

cd "`pathdata'"

spmap magnitud1 using MEX_coord, id(id) fcolor(BuPu) clm(unique) osize(vvvthin ..) nds(vvvthin ..) ndfcolor(gs14) oc(white) ndo(gs12) ndl("No Impact") /*
*/ legend(size(medium))

local pathdata2 "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\OutputN"
cd "`pathdata2'"
graph export EQintensity.png, width(1500) height(1000) replace

/*
spmap earthquake using MEX_coord, id(id) fcolor(PiYG) clm(unique) osize(vvthin) oc(white) ndo(none ..) /*
*/ legend(size(medium)) 

local pathdata2 "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 25 Terremotos\Output"
cd "`pathdata2'"
graph export equake.png, width(800) height(600) replace

g eqGM = earthquake*GM

label define eGM 0 "No Impact" 1 "Impact, Very Low Marg." 2 "Impact, Low Marg." 3 "Impact, Medium Marg." 4 "Impact, High Marg." 5 "Impact, Very High Marg."
label values eqGM eGM 

local pathdata "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 25 Terremotos\Data\Mapa"
cd "`pathdata'"

spmap eqGM using MEX_coord, id(id) fcolor(Paired) clm(unique) osize(vvthin ..) ndfcolor(gs5) oc(white) ndo(none ..) /*
*/ legend(size(medium))

local pathdata2 "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 25 Terremotos\Output"
cd "`pathdata2'"
graph export EarthquakeGM.png, width(800) height(600) replace
*/
clear
